/*
 * 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙，邂逅框架梦]
 * 
 * 知启蒙Servlet兼容库（zhiqim_servlet）在LGPL3.0协议下开源：https://www.zhiqim.com/gitcan/zhiqim/zhiqim_servlet.htm
 *
 * This file is part of [zhiqim_servlet].
 * 
 * [zhiqim_servlet] is free software: you can redistribute
 * it and/or modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 * 
 * [zhiqim_servlet] is distributed in the hope that it will
 * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with [zhiqim_servlet].
 * If not, see <http://www.gnu.org/licenses/>.
 */
package org.zhiqim.calendar;

import org.zhiqim.calendar.dbo.ZmrCalendar;

import org.zhiqim.kernel.annotation.AnAlias;
import org.zhiqim.kernel.Global;
import org.zhiqim.httpd.HttpRequest;
import org.zhiqim.httpd.context.annotation.AnIntercept;
import org.zhiqim.orm.ZTable;
import org.zhiqim.kernel.util.DateTimes;

/**
 * 日历页面调用器
 *
 * @version v1.0.0 @author zouzhigang 2017-11-8 新建与整理
 */
@AnAlias("ZmrCalendarPresenter")
@AnIntercept("chkZmrLogin")
public class ZmrCalendarPresenter 
{
    /**
     * 切换工作日和休息日
     * 
     * @param request       请求对象
     * @param calendarDate  日历日期
     * @throws Exception    异常
     */
    public static void doToggle(HttpRequest request, int calendarDate) throws Exception
    {   
       if((Global.get(ZTable.class).count(ZmrCalendar.class, calendarDate)) > 0)
       {//判断该日期在项目日历表中是否存在，存在就删除
           Global.get(ZTable.class).delete(ZmrCalendar.class, calendarDate);
           return;
       }

       //不存在则增加，周末就设置为工作日，否则设置为休息日
       ZmrCalendar calendar = new ZmrCalendar();
       calendar.setCalendarDate(calendarDate);
       int week = DateTimes.getDateWeek7(calendarDate);
       if (week == 6 || week == 7)
           calendar.setCalendarRest(false);
       else
           calendar.setCalendarRest(true);
       
       Global.get(ZTable.class).insert(calendar);
    }
}
